#!/usr/bin/env bash
# Copyright (c) 2024 maminjie <canpool@163.com>
# SPDX-License-Identifier: MulanPSL-2.0

usage() {
    echo "usage: bash oe_genrepo.sh OE_VERSION"
}

REPO_URL_PREFIX="https://mirrors.jxust.edu.cn/openeuler"

repo_file_template='
[OS]
name=OS
baseurl=REPO_URL_PREFIX/OEVER/OS/$basearch/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/OS/$basearch/RPM-GPG-KEY-openEuler

[everything]
name=everything
baseurl=REPO_URL_PREFIX/OEVER/everything/$basearch/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/everything/$basearch/RPM-GPG-KEY-openEuler

[EPOL]
name=EPOL
baseurl=REPO_URL_PREFIX/OEVER/EPOL/main/$basearch/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/OS/$basearch/RPM-GPG-KEY-openEuler

[debuginfo]
name=debuginfo
baseurl=REPO_URL_PREFIX/OEVER/debuginfo/$basearch/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/debuginfo/$basearch/RPM-GPG-KEY-openEuler

[source]
name=source
baseurl=REPO_URL_PREFIX/OEVER/source/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/source/RPM-GPG-KEY-openEuler

[update]
name=update
baseurl=REPO_URL_PREFIX/OEVER/update/$basearch/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/OS/$basearch/RPM-GPG-KEY-openEuler

[update-source]
name=update-source
baseurl=REPO_URL_PREFIX/OEVER/update/source/
enabled=1
gpgcheck=1
gpgkey=REPO_URL_PREFIX/OEVER/source/RPM-GPG-KEY-openEuler
'

if [ $# -lt 1 ]; then
    usage; exit
fi

echo "$repo_file_template" | sed -e "s|OEVER|$1|g" -e "s|REPO_URL_PREFIX|$REPO_URL_PREFIX|g"
